package com.faithbj.danaliverpool.web.controller.admin;

import java.io.IOException;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.faithbj.common.configuration.Pager;
import com.faithbj.common.model.Dictionary;
import com.faithbj.danaliverpool.service.DictionaryService;

/**
 * @author jrn E-mail: rinanjin@gmail.com
 * @version 0.1 
 * 创建时间：2012-6-8 下午11:41:35
 * 类说明
 */
@Controller
@RequestMapping("/faith/dictionary")
public class AdminDictionaryController extends BaseAdminController
{
	private static final long serialVersionUID = 1L;

	@Resource
	private DictionaryService dictionaryService;
	
	private static final String LIST = "/admin/dictionary_list";
	
	private static final String INPUT = "/admin/dictionary_input";
	
	private static final String OPERRATE_RETURN_URL = "dictionary/list";
	
	@RequestMapping(value = "/list")
	public String list(@ModelAttribute() Pager pager, ModelMap map) throws IOException
	{
		Pager pagerVal = dictionaryService.findByPager(pager);
		map.put("pager", pagerVal);
		return LIST;
	}
	
	@RequestMapping(value = "add")
	public String add(ModelMap map)
	{
		map.put("isAddAction", true);
		return INPUT;
	}
	
	@RequestMapping(value = "delete")
	public String delete(@RequestParam("id") String id, ModelMap map)
	{
		dictionaryService.delete(id);
		dictionaryService.flush();
		
		map.put("redirectUrl", OPERRATE_RETURN_URL);
		return SUCCESS;
	}
	
	@RequestMapping(value = "save")
	public String save(@ModelAttribute("dictionary") Dictionary dictionary, ModelMap map)
	{
		dictionaryService.save(dictionary);
		dictionaryService.flush();
		
		map.put("redirectUrl", OPERRATE_RETURN_URL);
		return SUCCESS;
	}
}
